// pages/inviation/index.js
const app = getApp()
Page({

     /**
      * 页面的初始数据
      */
     data: {
          userInfo: {},
          setting: {}
     },

     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
          wx.setNavigationBarTitle({
               title: '邀请有礼',
          })
          let that = this;
          //设置
          app.connect('index/setting', {}, function (res) {
               that.setData({
                    setting: res
               });
          });
          //登录
          app.login(function (userInfo) {
               that.setData({
                    userInfo: userInfo.data
               });
               //校验有没有绑定手机号，没有绑定则跳出绑定页
     
               if (!app.isPoneAvailable(userInfo.data.mobile)) {
                   
                    wx.showModal({
                         title: '提示',
                         content:'您还没有绑定手机号,请先绑定手机号',
                         showCancel:false,
                         cancelText:'前往绑定',
                         success: function (res) {
                              if (res.confirm) {
                                   if(that.data.userInfo.invi_uid == '') {
                                        wx.redirectTo({
                                             url: '../login/index'
                                        })
                                   }else{
                                        wx.redirectTo({
                                             url: '../inviation/login?invi_uid=' + that.data.userInfo.invi_uid
                                        })
                                   }
                                  
                              }
                         }
                    })
               }
               //生产用户自己独一无二的分享小程序码


               app.connect('account/getInviQrcode', {
                    uid: that.data.userInfo.uid,
                    openid: that.data.userInfo.openId
               }, function (res) {
                    console.log(res);
               });


          });
     },
     /**
          * 转发邀请别人
          */
     onShareAppMessage: function (res) {
          let that = this;
          console.log(that.data.userInfo.uid);
          return {
               title: '送你一个MAG红包，打开麦颜值就能拆开',
               path: 'pages/inviation/login?invi_uid=' + that.data.userInfo.uid,
               imageUrl: '../icon/share.png'
          }
     },
     tiao: function () {
          wx.navigateTo({
               url: 'createPic',
          })
     }
})